﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace Magiq.Insert
{
    public class Insert<TSourceCollection, TDestination, TNew> : IInsert<TSourceCollection, TDestination, TNew>, IInsert
        where TDestination : class
        where TNew : class, TDestination, new() 
    {
        public Insert(Expression<Func<TSourceCollection, TNew>> insertExpression, InsertSource<TNew> insertSource, IQueryable<TDestination> destination)
        {
            NewExpression = insertExpression;
            Source = insertSource;
            Destination = destination;
        }
        
        public int Execute()
        {
            var strategy = MagiqConfigurator.ForInsert(this);
            return strategy.Execute();
        }

        public Expression<Func<TSourceCollection, TNew>> NewExpression { get; private set; }
        public InsertSource<TNew> Source { get; private set; }
        public IQueryable<TDestination> Destination { get; private set; }
    }
}